package com.newworld.dmsapp2.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/** 
 *  
 * 
 * 
 */
public class MyPreference {
	private static MyPreference preference = null;
	private static SharedPreferences sharedPreference;
	private String packageName = "";

	private static final String SQL_INIT = "sql_init";
	private static final String USER_ID = "user_id";
	private static final String REGISTER_ID = "register_id";
	private static final String REFRESH_STATE = "refresh_state";// true:自动刷新
																// false:下拉刷新
	private static final String VERSION_CODE = "version_code";
	private static final String SERVER_URL = "server_url";
	private static final String UPDATE_URL = "update_url";
	private static final String MESSAGE_URL = "message_url";

	public static synchronized MyPreference getInstance(Context context) {
		if (preference == null)
			preference = new MyPreference(context);
		return preference;
	}

	public MyPreference(Context context) {
		packageName = context.getPackageName() + "_preferences";
		sharedPreference = context.getSharedPreferences(packageName,
				Context.MODE_PRIVATE);
	}

	public int getVersionCode() {

		int code = sharedPreference.getInt(VERSION_CODE, 0);
		return code;
	}

	public void setVersionCode(int code) {
		Editor editor = sharedPreference.edit();
		editor.putInt(VERSION_CODE, code);
		editor.commit();

	}

	public boolean getSqlInit() {
		boolean param = sharedPreference.getBoolean(SQL_INIT, false);
		return param;
	}

	public void setSqlInit(boolean param) {
		Editor editor = sharedPreference.edit();
		editor.putBoolean(SQL_INIT, param);
		editor.commit();
	}

	public boolean getRefreshState() {
		boolean param = sharedPreference.getBoolean(REFRESH_STATE, false);
		return param;
	}

	public void setRefreshState(boolean param) {
		Editor editor = sharedPreference.edit();
		editor.putBoolean(REFRESH_STATE, param);
		editor.commit();
	}

	public long getUserId() {
		long stuName = sharedPreference.getLong(USER_ID, 0);
		return stuName;
	}

	public void setUserId(long userid) {
		Editor editor = sharedPreference.edit();
		editor.putLong(USER_ID, userid);
		editor.commit();
	}

	public long getRegisterrId() {
		long stuName = sharedPreference.getLong(REGISTER_ID, 0);
		return stuName;
	}

	public void setRegisterId(long userid) {
		Editor editor = sharedPreference.edit();
		editor.putLong(REGISTER_ID, userid);
		editor.commit();
	}

	public String getServerUrl() {
		String serverUrl = sharedPreference.getString(SERVER_URL, "");
		return serverUrl;
	}

	public void setServerUrl(String ip) {
		Editor editor = sharedPreference.edit();
		editor.putString(SERVER_URL, ip);
		editor.commit();
	}

	public static String getUpdateUrl() {
		String serverUrl = sharedPreference.getString(UPDATE_URL, "");
		return serverUrl;
	}

	public static String getMessageUrl() {
		String serverUrl = sharedPreference.getString(MESSAGE_URL, "");
		return serverUrl;
	}

	public void setUpdateUrl(String ip) {
		Editor editor = sharedPreference.edit();
		editor.putString(UPDATE_URL, ip);
		editor.commit();
	}

	public void setMessageUrl(String ip) {
		Editor editor = sharedPreference.edit();
		editor.putString(MESSAGE_URL, ip);
		editor.commit();
	}

}
